#include "stun_protocol_operation.h"

#include "./../stun_protocol/stun_protocol_msg.h"
#include "./../stun_protocol/stun_protocol_parser.h"
#include "protocol_operation.h"

#include <cstdint>

StunProtocolOperation::StunProtocolOperation()
{
    m_parser = new StunProtocolParser();
}

StunProtocolOperation::~StunProtocolOperation()
{
    delete m_parser;
    m_parser = nullptr;
}

int StunProtocolOperation::ParserProtocol(const uint8_t * data, int data_length, int & use_length)
{
    m_parser->ResetStunMsg();
    int result = m_parser->ParserStunMsg(data, data_length, use_length);
    if (StunProtocolParser::FINISH == result)
    {
        return ProtocolOperation::FINISH;
    }
    else if (StunProtocolParser::NEED_DATA == result)
    {
        return ProtocolOperation::NEED_DATA;
    }
    return ProtocolOperation::BAD;
}

StunMsg * StunProtocolOperation::GetStunMsg()
{
    m_msg = m_parser->StunMsgPtr();
    return m_msg.get();
}
